package com.mms.util;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.mms.dao.MyMeetingDao;
import com.mms.entity.Meeting;

public class MyMeetingInfo {
           public static HttpServletRequest getMyMeetingInfo(HttpServletRequest request){
               MyMeetingDao myMeetingDao=new MyMeetingDao(Integer.parseInt(request.getSession().getAttribute("userID").toString()));
               List<Meeting> meetingIn7=null;
               List<Meeting> meetingMyOrder=null;
               List<Meeting> meetingEnded=null;
               List<Meeting> meetingCanceled=null;
               
               String type=request.getParameter("type");
               if (type!=null&&type!="") {
                   if(type.equals("future7")){
                      int pageFuture7=Integer.parseInt(request.getParameter("pageFuture7"));
                      int accountFuture7=myMeetingDao.getMeetingInWeeksCount();
                      meetingIn7=myMeetingDao.getMeetingInWeeks(pageFuture7);
                      meetingMyOrder=myMeetingDao.getMeetingMyOrder(Integer.parseInt(request.getSession().getAttribute("userID").toString()), 0);
                      meetingEnded=myMeetingDao.getEndedMeeting(0);
                      meetingCanceled=myMeetingDao.getCaneledMeeting(0);
                      request.setAttribute("pageFuture7",pageFuture7);
                      request.setAttribute("accountFuture7",accountFuture7);
                   }
                   else if (type.equals("myOrder")) {
                       int pageMyOrder=Integer.parseInt(request.getParameter("pageMyOrder"));
                       int accountMyOrder=myMeetingDao.getMeetingMyOrderCount(Integer.parseInt(request.getSession().getAttribute("userID").toString()));
                       meetingMyOrder=myMeetingDao.getMeetingMyOrder(Integer.parseInt(request.getSession().getAttribute("userID").toString()), pageMyOrder);
                       meetingIn7=myMeetingDao.getMeetingInWeeks(0);
                       meetingEnded=myMeetingDao.getEndedMeeting(0);
                       meetingCanceled=myMeetingDao.getCaneledMeeting(0);
                       request.setAttribute("pageMyOrder",pageMyOrder);
                       request.setAttribute("accountMyOrder",accountMyOrder);
                   }
                   else if (type.equals("ended")) {
                       int pageEnded=Integer.parseInt(request.getParameter("pageEnded"));
                       int accountEnded=myMeetingDao.getEndedMeetingCount();
                       meetingEnded=myMeetingDao.getEndedMeeting(pageEnded);
                       meetingMyOrder=myMeetingDao.getMeetingMyOrder(Integer.parseInt(request.getSession().getAttribute("userID").toString()), 0);
                       meetingIn7=myMeetingDao.getMeetingInWeeks(0);
                       meetingCanceled=myMeetingDao.getCaneledMeeting(0);
                       request.setAttribute("pageEnded",pageEnded);
                       request.setAttribute("accountEnded",accountEnded);
                   }
                   else if (type.equals("canceled")) {
                       int pageCanceled=Integer.parseInt(request.getParameter("pageCanceled"));
                       int accountCanceled=myMeetingDao.getCanceledMeetingCount();
                       meetingCanceled=myMeetingDao.getCaneledMeeting(pageCanceled);
                       meetingEnded=myMeetingDao.getEndedMeeting(0);
                       meetingMyOrder=myMeetingDao.getMeetingMyOrder(Integer.parseInt(request.getSession().getAttribute("userID").toString()), 0);
                       meetingIn7=myMeetingDao.getMeetingInWeeks(0);
                       request.setAttribute("pageCanceled",pageCanceled);
                       request.setAttribute("accountCanceled",accountCanceled);
                   }
               }
               else {
                   System.out.println("flag!!!");
                    meetingIn7=myMeetingDao.getMeetingInWeeks(0);
                    meetingMyOrder=myMeetingDao.getMeetingMyOrder(Integer.parseInt(request.getSession().getAttribute("userID").toString()), 0);
                    meetingEnded=myMeetingDao.getEndedMeeting(0);
                    meetingCanceled=myMeetingDao.getCaneledMeeting(0);
               }
               request.setAttribute("meetingList", meetingIn7);
               request.setAttribute("meetingMyOrder", meetingMyOrder);
               request.setAttribute("meetingEnded", meetingEnded);
               request.setAttribute("meetingCanceled", meetingCanceled);
               request.setAttribute("accountCanceled",myMeetingDao.getCanceledMeetingCount());
               request.setAttribute("accountEnded",myMeetingDao.getEndedMeetingCount());
               request.setAttribute("accountFuture7",myMeetingDao.getMeetingInWeeksCount());
               request.setAttribute("accountMyOrder",myMeetingDao.getMeetingMyOrderCount(Integer.parseInt(request.getSession().getAttribute("userID").toString())));
               return request;
           } 
}
